package com.msconfig.mvp.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.geo.msconfig.R;
import com.msconfig.event.OtherCommunicationDialogDismissEvent;

import org.greenrobot.eventbus.EventBus;

import static com.msconfig.mvp.view.fragment.SetupSurveyStationFragment.COMMUNICATIONSETUP;

public class SetupOtherCommunicationDialogActivity extends Activity implements View.OnClickListener{
    private RelativeLayout rlClose;
    private TextView tvClose;
    private RelativeLayout rlTcpClient;
    private TextView tvTcpClient;
    private RelativeLayout rlTcpServer;
    private TextView tvTcpServer;
    private CheckBox cbClose;
    private CheckBox cbClient;
    private CheckBox cbServer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_activity_setup_other_communication_dialog);
        rlClose = (RelativeLayout)findViewById( R.id.rl_close );
        tvClose = (TextView)findViewById( R.id.tv_close );
        rlTcpClient = (RelativeLayout)findViewById( R.id.rl_tcp_client );
        tvTcpClient = (TextView)findViewById( R.id.tv_tcp_client );
        rlTcpServer = (RelativeLayout)findViewById( R.id.rl_tcp_server );
        tvTcpServer = (TextView)findViewById( R.id.tv_tcp_server );
        cbClose = (CheckBox) findViewById( R.id.cb_close );
        cbClient = (CheckBox) findViewById( R.id.cb_tcp_client );
        cbServer = (CheckBox) findViewById( R.id.cb_tcp_server );

        rlClose.setOnClickListener(this);
        rlTcpClient.setOnClickListener(this);
        rlTcpServer.setOnClickListener(this);

        //选中已选择的
        Intent intent=getIntent();
        String data=intent.getStringExtra(COMMUNICATIONSETUP);
        if(data.equals("TCP服务端")){
            cbServer.setChecked(true);
        }else if(data.equals("TCP客户端")){
            cbClient.setChecked(true);
        }else{
           cbClose.setChecked(true);
        }

    }

    @Override
    public void onClick(View v) {
        if(v==rlClose){
            EventBus.getDefault().post(new OtherCommunicationDialogDismissEvent(tvClose.getText().toString().trim()));
            finish();
        }else if(v==rlTcpClient){
            EventBus.getDefault().post(new OtherCommunicationDialogDismissEvent(tvTcpClient.getText().toString().trim()));
            finish();
        }else if(v==rlTcpServer){
            EventBus.getDefault().post(new OtherCommunicationDialogDismissEvent(tvTcpServer.getText().toString().trim()));
            finish();
        }

    }
}
